﻿using System.Linq;

namespace Mathematics.Expressions
{
    internal delegate ExpressionValue AssignableFunction(params ExpressionValue[] parameters);

    internal class SystemFunctionDefinition:FunctionDefinition
    {
        public SystemFunctionDefinition(string name, AssignableFunction function, params ParameterDefinition[] parameters) 
            : base(name, parameters)
        {
            Function = function;
        }

        public AssignableFunction Function { get; private set; }

        internal override ExpressionValue Invoke(FunctionCall call)
        {
            return Function(call.Parameters.Select(p => p.Evaluate()).ToArray());
        }

        public override bool CanEvaluate()
        {
            return true;
        }
    }
}
